extends Node2D

# 导出变量，方便在编辑器中调整
@export var move_length: float = 100.0  # 移动长度
@export_enum("horizontal", "vertical") var move_direction: String = "horizontal"  # 移动方向
@export var speed: float = 50.0  # 移动速度
@export var delay: float = 1.0  # 移动后的延迟时间

@onready var tween: Tween
var previous_position: Vector2  # 新增变量记录上一帧位置

func _ready():
	previous_position = position  # 初始化位置记录
	# 创建 Tween
	tween = create_tween()

	# 记录平台初始位置
	var start_position = position

	# 根据方向计算目标位置
	var target_position = start_position
	match move_direction:
		"horizontal":
			target_position += Vector2(move_length, 0)
		"vertical":
			target_position += Vector2(0, move_length)
	
	# 计算移动时间
	var duration = move_length / speed

	# 使用 Tween 实现平台移动
	tween.tween_property(self, "position", target_position, duration).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN_OUT).set_delay(delay)
	tween.tween_property(self, "position", start_position, duration).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN_OUT).set_delay(delay * 2)
	tween.set_loops()  # 无限循环

	
